

var lmsg = new Vue({
	el: "#Luser",
	data: {
		info: initInfo()
	},
	methods: {
		getTel(item) {
			return item
		},
		getUid(item) {

			return item
		},
		getImgUrl(item) {
			var url = 'http://114.55.145.243:8080/img/img/' + item + '.jpg'
			return url
		},
		getUserClass(item) {
							if(item == "女")
								return 'gender famale';
							if(item == "男")
								return 'gender male';
							}
	}
})

function initInfo() {
	getProvince()
	var list;
	$.ajax({
		url: "http://114.55.145.243:8080/liantu/Login/UsersServlet/loginUserById",
		//url:"http://localhost:8080/javaproject/Login",
		async: false,
		xhrFields: {
			withCredentials: true
		},

		success: function(data) {
			if(data.data) {
				$("#logining").css("width", "130px");
				$("#logining").prop("href", "member_info.html")
				$("#logining").html(data.data.user_tel);
				if(data.data.user_dis==3){
					$("#sqdy").html("")
				}
				setSex(data.data.user_sex)
				
				setCity(data.data.user_city)
				setAge(data.data.user_age)
				list = data.data

			} else
				alert(data.msg)
		},
		dataType: "json"
	})
	return list;
}

function setCity(city) {

	for(var i = 0; i < provinceList.length; i++) {
		for(var j = 0; j < provinceList[i].cityList.length; j++) {
			if(provinceList[i].cityList[j].name == city) {
				$("#province option[value='" + provinceList[i].name + "']").attr("selected", true);

			}
			if(provinceList[i].name == city) {
				$("#province option[value='" + provinceList[i].name + "']").attr("selected", true);
			}

		}
	}
	chooseProvince(document.querySelector("#province"))
	$("#city option[value='" + city + "']").attr("selected", true);
}
function setSex(sex) {

	$("#user_sex[value='" + sex + "']").attr("checked", true);
	
}

function setAge(age){

	$("#user_age option[value='" + age + "']").attr("selected", true);
}


//接收一个值
function oneValues() {
	var result;
	var url = window.location.search; //获取url中"?"符后的字串  
	if(url.indexOf("?") != -1) {
		result = url.substr(url.indexOf("=") + 1);
	}
	return result;

}

function sumitInfo(){
	var oError = document.getElementById("error_box")
	if($("#city").val()=="市辖区"||$("#city").val()=="县"){
		$("#province").attr("name","user_city")
	}
	else{
		$("#city").attr("name","user_city")
	}
	//提交到数据库
	$.ajax({
		url: "http://114.55.145.243:8080/liantu/Login/UsersServlet/updateMsgByTel",
		async: false,
		xhrFields: {
			withCredentials: true
		},
		data: $("form").serialize(),
		success: function(data) {
			if(data.status){
				alert("修改成功")
				location.reload()
			}
			else
				oError.innerHTML="修改失败"
		},
		dataType: "json"
	})
}


